#!/bin/bash
# wrk压力测试执行脚本

echo "Starting wrk performance test..."

# 从环境变量获取测试参数
URL=${TEST_URL:-"http://backend:1226"}
THREADS=${TEST_THREADS:-4}
CONNECTIONS=${TEST_CONNECTIONS:-100}
DURATION=${TEST_DURATION:-30}

echo "Test URL: $URL"
echo "Threads: $THREADS"
echo "Connections: $CONNECTIONS"
echo "Duration: ${DURATION}s"

# 执行wrk测试
wrk -t$THREADS -c$CONNECTIONS -d${DURATION}s \
    --timeout 30s \
    --script=./scripts/performance.lua \
    $URL > ./results/wrk-output.txt

# 生成JSON格式结果
echo "Generating JSON report..."
cat ./results/wrk-output.txt | ./scripts/parse-results.js > ./results/report.json

echo "Performance test completed."